/**
 * 通入气体
 */
Gas = Widget.extend({
	ctor:function(){
		this._super();
		this.initCatheter();
		this.setTag(TAG_GAS);
	},
	initCatheter:function(){			
			if(gg.flow.flow.action==ACTION_DO1){
				this.intoNH3();
			}else if(gg.flow.flow.action==ACTION_DO2){			
				this.loadNH3();
			}else{
				this.intoCO2();
			}
	},
	intoNH3:function(){
		var nh3 = new Button(this, 10, TAG_NH3,"#nh3.png", this.callback);
		nh3.setPosition(cc.p(145,-60));
		var seq=cc.sequence(cc.delayTime(1),cc.callFunc(function() {
			this.schedule(this.loadArrow, 0.3);
		}, this),cc.callFunc(function() {
			var show=new ShowTip("必须优先通入氨气，氨气易溶于水\n" +
			"可以为二氧化碳营造碱性环境，增加其溶解度" ,cc.p(980,260));
		}, this),cc.delayTime(0.5),cc.callFunc(function() {
			this.schedule(this.loadBubble,0.3);
		}, this),cc.delayTime(1),cc.callFunc(function() {
			gg.flow.next();
		}, this));
		nh3.runAction(seq);
	},
	intoCO2:function(){
		var co2 = new Button(this, 10, TAG_CO2,"#co2.png", this.callback);
		co2.setPosition(cc.p(145,-60));
		var seq=cc.sequence(cc.delayTime(1),cc.callFunc(function() {
			this.schedule(this.loadArrow, 0.3);
			var show=new ShowTip("再通入二氧化碳，至沉淀生成即可停止通气，\n" +
					"反应方程为：NH₃ + CO₂ + H₂O = NH₄HCO₃\n" +
					"NH₄HCO₃ + NaCl = NH₄Cl + NaHCO₃ ↓" ,cc.p(980,260));
		}, this),cc.delayTime(0.5),cc.callFunc(function() {
			this.schedule(this.loadBubble,0.3);
			var deposit1=new cc.Sprite("#deposit1.png");
			deposit1.setPosition(cc.p(30,17));
			deposit1.setScale(2, 1);
			deposit1.setOpacity(0);
			var beaker1=this.getParent().getChildByTag(TAG_BUNSEN1).getChildByTag(TAG_BEAKER1);
			beaker1.addChild(deposit1,2,TAG_DEPOSIT1);
			var seq=cc.sequence(cc.delayTime(1),cc.fadeIn(2));
			deposit1.runAction(seq);
		}, this),cc.delayTime(2.5),cc.callFunc(function() {
			
			gg.flow.next();
		}, this));
		co2.runAction(seq);
	},
	loadNH3:function(){
		var nh3 = new Button(this, 10, TAG_NH3,"#nh3.png", this.callback);
		nh3.setPosition(cc.p(145,-60));

		var seq=cc.sequence(cc.delayTime(1),cc.callFunc(function() {
			this.schedule(this.loadArrow, 0.3);
		}, this),cc.callFunc(function() {
			var show=new ShowTip("因为NH₄Cl在NaCl的浓溶液里的溶解度\n会小很多，" +
					"所以加入精盐和通入氨气，至\nNH₄Cl结晶沉淀析出即可停止通气"  ,cc.p(970,260));
		}, this),cc.delayTime(0.5),cc.callFunc(function() {
			this.schedule(this.loadBubble,0.3);
		}, this),cc.delayTime(1),cc.callFunc(function() {
			var salt=this.getParent().getChildByTag(TAG_BUNSEN2).getChildByTag(TAG_BEAKER2).getChildByTag(TAG_SALT);
			var sca=cc.scaleTo(2,2,1);
			var mov=cc.moveTo(2, cc.p(29,21));
			var fadeout=cc.fadeOut(2);
			var spa=cc.spawn(sca,mov,fadeout);			
			var fadein=cc.fadeIn(1);
			var seq=cc.sequence(spa,cc.delayTime(0.5),fadein,cc.callFunc(function() {
				gg.flow.next();
			}, this));
			salt.runAction(seq);
		}, this));
		nh3.runAction(seq);
	},
	loadArrow:function(){	
		var nh3=this.getChildByTag(TAG_NH3);
		var arrow=new cc.Sprite("#arrow.png");		
		this.addChild(arrow,3,TAG_ARROW);
		arrow.setPosition(cc.p(100,-61));
		var move=cc.moveTo(0.6, cc.p(-35,-61));
		var seq=cc.sequence(move,cc.callFunc(function() {
			arrow.removeFromParent();
		}, this),cc.delayTime(2),cc.callFunc(function() {

		}, this));
		arrow.runAction(seq);
	},
	stopArrow:function(){
		this.unschedule(this.loadArrow);
	},
	loadBubble:function(){
		var bubble=new cc.Sprite("#bubble1.png");
		this.addChild(bubble,4);
		bubble.setPosition(cc.p(-56,-144));
		var ber = cc.bezierBy(1,[cc.p(0,0),cc.p(-20,-15),cc.p(-30,30)]);
		var seq=cc.sequence(ber,cc.callFunc(function() {
			bubble.removeFromParent();
		}, this));
		bubble.runAction(seq);
	},
	kill:function(){
		var seq = cc.sequence(cc.fadeOut(0.5),cc.callFunc(function(){
			this.removeFromParent(true);
		},this));
		this.runAction(seq);
	},
});